<template>
  <!--企业认证-->
  <div class="statistics-container">
    <vab-query-form>
      <vab-query-form-right-panel :span="50">
        <el-form :inline="true" :model="queryForm" @submit.native.prevent>
          <el-form-item>
            <el-input
              v-model.trim="queryForm.keyword"
              style="margin-right: 10px"
              placeholder="请输入用户名或手机号"
              clearable
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="search()">
              查询
            </el-button>
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-refresh-right"
              @click="restart"
            >
              重置
            </el-button>
          </el-form-item>
        </el-form>
      </vab-query-form-right-panel>
    </vab-query-form>

    <el-table
      v-loading="listLoading"
      :data="list"
      @selection-change="setSelectRows"
    >
      <el-table-column
        align="center"
        show-overflow-tooltip
        label="序号"
        sortable
        type="index"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="appid_info.nickname"
        label="用户名"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="appid_info.mobile"
        label="手机号"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="auth_data.company_name"
        label="认证公司名"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="auth_data.s_number"
        label="认证税号"
      />
      <el-table-column align="center" show-overflow-tooltip label="营业执照">
        <template #default="{ row }">
          <el-image
            style="width: 60px; height: 60px"
            :src="row.auth_data.yy_img"
            :preview-src-list="[row.auth_data.yy_img]"
          />
        </template>
      </el-table-column>
      <!-- <el-table-column align="center" show-overflow-tooltip label="开户许可证">
        <template #default="{ row }">
          <el-image
            style="width: 60px; height: 60px"
            :src="row.auth_data.kh_img"
            :preview-src-list="[row.auth_data.kh_img]"
          />
        </template>
      </el-table-column> -->
      <el-table-column align="center" label="操作">
        <template slot-scope="scope">
          <el-button v-if="scope.row.status === 2" type="text" @click="pass(scope.row)">认证通过</el-button>
          <el-button v-if="scope.row.status === 2" type="text" @click="bohui(scope.row)">驳回</el-button>
          <el-button v-if="scope.row.status === 3" type="text" @click="infos(scope.row)">驳回信息</el-button>
          <div v-if="scope.row.status === 1">已通过</div>
        </template>
      </el-table-column>
    </el-table>

    <!-- 驳回信息 -->
    <el-dialog title="驳回信息" :visible.sync="dialogDetail" width="500px" top="30vh">
      <div>{{ backContent }}</div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogDetail = false">
          确 定
        </el-button>
      </div>
    </el-dialog>
    <!-- 填写驳回信息 -->
    <el-dialog title="填写驳回信息" :visible.sync="dialogDetail2" width="500px" top="30vh">
      <el-input
        v-model.trim="msg"
        placeholder="请输入驳回内容"
        type="textarea"
        clearable
      />
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogDetail2 = false">
          取消
        </el-button>
        <el-button type="primary" @click="pass2">
          确定
        </el-button>
      </div>
    </el-dialog>

    <el-pagination
      background
      :current-page="queryForm.page"
      :page-size="queryForm.list_row"
      :layout="layout"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
  import { getCompanyAuthLists,editCompanyAuths } from '@/api/common'

  export default {
    name: 'User',
    data() {
      return {
        queryForm: {
          page: 1,
          list_row: 10,
          keyword: '',
        },
        listLoading: false,
        list: [],
        labels: [],
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        dialogDetail: false,
        dialogDetail2: false,
        backContent: '',
        msg:'',
        sel_id:0,
      }
    },
    created() {
      this.getData()
    },
    methods: {
      pass2(){
        let param = {
          id:this.sel_id,
          type:2,
          msg:this.msg
        }
        if(this.msg === ''){
          this.$message.error('驳回内容不能为空！')
          return false
        }
        editCompanyAuths(param).then(res=>{
          console.log(222,res)
          if(res.code === 2000){
            this.$message.success('驳回成功！')
            //this.dialogFormVisible = false
            this.getData()
          }
        })
        this.dialogDetail2 = false;
      },
      pass(row){
        let param = {
          id:row.id,
          type:1,
        }
        editCompanyAuths(param).then(res=>{
          console.log(222,res)
          if(res.code === 2000){
            this.$message.success('认证通过！')
            //this.dialogFormVisible = false
            this.getData()
          }
        })
      },
      bohui(row){
        this.msg = ''
        this.sel_id = row.id;
        this.dialogDetail2 = true;
      },
      handleDetail() {},
      restart() {
        this.queryForm = []
        this.getData()
      },
      //搜索
      search() {
        this.getData()
      },
      getData() {
        let params = {
          page: this.queryForm.page,
          limit: this.queryForm.list_row,
          search_input: this.queryForm.keyword,
        }
        getCompanyAuthLists(params).then((data) => {
          this.list = data.data
          this.total = data.count
        })
      },
      infos(row) {
        this.dialogDetail = true
        this.backContent = row.return_data.msg
      },
      setSelectRows() {},
      handleSizeChange(val) {
        this.queryForm.list_row = val
        this.getData()
      },
      handleCurrentChange(val) {
        this.queryForm.page = val
        this.getData()
      },
    },
  }
</script>

<style lang="scss" scoped>
  .el-button {
    font-size: 14px;
    margin-right: 20px;
  }
</style>
